<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>商家详情</title>
    <link rel="shortcut icon" href="/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache, must-revalidate">
    <meta http-equiv="Cache" content="no-cache">

    <link rel="stylesheet" href="/sui/css/sm.min.css">
    <link rel="stylesheet" href="/sui/css/sm-extend.min.css">
    <link rel="stylesheet" href="/css/agency/enterprise/userDetail.css">
</head>
<body>

<div class="page-group">
    <!-- 单个page ,第一个.page默认被展示-->
    <div class="page">
        <header class="bar bar-nav" >
            <a href="/enterprise_user/list"  class="external button button-link button-nav pull-left">
                <span class="icon icon-left"></span>
                返回
            </a>
        </header>
        <div class="content">
            <ul class="sg_management">
                <li>
                    <a class="open-enterpriseDetail-popup">
                        <img src="/image/fenrun.png"/>
                        <span>分润设置</span>
                    </a>
                </li>
                <li>
                    <a class="agency_mch_terminal_btn">
                        <img src="/image/shebei.png"/>
                        <span>设备管理</span>
                    </a>
                </li>
                <li>
                    <a class="applyment">
                        <img src="/image/jinjian.png"/>
                        <span>商户进件</span>
                    </a>
                </li>
                <li>
                    <a class="configure">
                        <img src="/image/peizhi.png"/>
                        <span>商家配置</span>
                    </a>
                </li>
            </ul>
        </div>
    </div>

    <!--分润设置页面开始-->
    <div class="popup enterpriseDetail-popup" style="background-color: #efeff4!important;">
        <header class="bar bar-nav" style="line-height: 2.2rem">
            <a href="javascript:;" class="close-popup"  style="font-size:unset!important;line-height: unset!important;vertical-align: middle">
                <i style="display:inline-block;width:30px;height:30px;background-image: url(/image/guanbi.svg);background-position: center center;background-size: 30px 30px;margin: 0 0.5rem;vertical-align: middle"></i><span style="vertical-align: middle;color: #000000">切换分润</span>
            </a>
        </header>
        <form id="profit-form" onsubmit="return false" >
            <div class="list-block">
                <ul>
                    <li style="display: none">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label"></div>
                                <div class="item-input">
                                    <input  type="text" name="id" th:value="${mch.id}">
                                </div>
                            </div>
                        </div>
                    </li>

                    <!-- Text inputs -->
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">登录用户</div>
                                <div class="item-input">
                                    <input type="text" th:value="${mch.userName}" name="userName" disabled>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">手机号</div>
                                <div class="item-input">
                                    <input type="text" th:value="${mch.mobile}" name="mobile" disabled>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li class="profit-allocate">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">分润</div>
                                <div class="item-input">
                                    <select id="profit-select" th:attr="data-selected=${mch.profitId}" >

                                    </select>
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="content-block" >
                <div class="row" >
                    <div class="col-100"><a href="#" class="button button-big button-fill button-success" style="background: #0894ec">提交</a></div>
                </div>
            </div>

        </form>
    </div>

    <script type='text/javascript' src='/zepto/zepto.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/sui/js/sm.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/sui/js/sm-extend.min.js' charset='utf-8'></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.post('/enterprise_profit/queryData',function (result) {

                if(result.code==1){

                    var data=result.data;
                    var selectObj=$('#profit-select');
                    var profitId=selectObj.attr('data-selected');
                    for(var i=0;i<data.length;i++){
                        var profit_info=data[i];
                        var html='';
                        if(profitId==profit_info.id){
                            $('#profitName').text(profit_info.name);

                            html='<option selected="true" value='+ profit_info.id +'>'+profit_info.name+'</option>';
                            $('#profit-form .profit-allocate').find('select').append(html);
                        }else{
                            html='<option  value='+ profit_info.id +'>'+profit_info.name+'</option>';
                            $('#profit-form .profit-allocate').find('select').append(html);
                        }
                    }
                }
            });
            $(document).on('click','#profit-form .button-success',function () {

                var id= $("#profit-form input[name='id']").val();
                var mobile= $("#profit-form input[name='mobile']").val();
                var userName= $("#profit-form input[name='userName']").val();
                var profitId= $("#profit-select option").eq($("#profit-select").attr("selectedIndex")).val();
                var params={id:id,profitId:profitId,userName:userName,mobile:mobile};
                $.post('/enterprise_user/edit',params,function (result) {
                    if(result.code==1){
                        $.toast(result.message);
                        setTimeout(function () {
                            window.location.href="/enterprise_user/user_detail?userId="+id;
                        },500)

                    }else{
                        $.toast(result.message);
                    }
                })
            });
            $('.open-enterpriseDetail-popup').on('click',function () {
                $.popup('.enterpriseDetail-popup');
            });
            $(document).on('click','.agency_mch_terminal_btn',function () {
                var userId= $("#profit-form input[name='id']").val();
                window.location.href="/agency_mch_terminal/list?userId="+userId;
            });

            $(document).on('click','.applyment',function () {
                var userId= $("#profit-form input[name='id']").val();
                window.location.href="/applyment/index?userId="+userId;
            });

            $(document).on('click','.configure',function () {
                var userId= $("#profit-form input[name='id']").val();
                window.location.href="/enterprise_info/index?mchUserId="+userId;
            });

            $.init();
        })
    </script>
</div>

</body>
</html>

